#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int num;
		scanf("%d",&num);
		num-=964;
		int n1=num%10;
		int n2=num%12;
		printf("%d%c\n",n1,n2+'A');
	}
}

